package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.framework.web.page.TableDataInfoMy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.TbGoods;
import com.laowang.project.system.service.TbGoodsService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 商品Controller
 * 
 * @author laowang
 * @date 2022-12-19
 */
@Api(tags = "商品接口")
@RestController
@RequestMapping("/tbGoods")
public class TbGoodsController extends BaseController {


    @Autowired
    private TbGoodsService tbGoodsService;

    /**
     * 查询商品列表
     */
    @ApiOperation(value = "小程序端 查询商品列表",notes = "")
    @GetMapping("/wxApp/list")
    public TableDataInfoMy goodsList(Integer pageSize, Integer pageNum) {
        startPage();
        List<TbGoods> list = tbGoodsService.selectTbGoodsList(null);
        return getDataTableMy(list);
    }

    /**
     * 获取商品详细信息
     */
    @ApiOperation(value = "小程序端 获取商品详细信息",notes = "")
    @GetMapping(value = "/getDetail/{id}")
    public AjaxResult getDetail(@PathVariable("id") Long id) {
        return AjaxResult.success(tbGoodsService.selectTbGoodsById(id));
    }


    /**
     * 查询商品列表
     */
    @ApiOperation(value = "查询商品列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:tbGoods:list')")
    @GetMapping("/list")
        public TableDataInfo list(TbGoods tbGoods) {
        startPage();
        List<TbGoods> list = tbGoodsService.selectTbGoodsList(tbGoods);
        return getDataTable(list);
    }
    
    /**
     * 导出商品列表
     */
    @ApiOperation(value = "导出商品列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:tbGoods:export')")
    @Log(title = "商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbGoods tbGoods) {
        List<TbGoods> list = tbGoodsService.selectTbGoodsList(tbGoods);
        ExcelUtil<TbGoods> util = new ExcelUtil<TbGoods>(TbGoods.class);
        return util.exportExcel(list, "tbGoods");
    }

    /**
     * 获取商品详细信息
     */
    @ApiOperation(value = "获取商品详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('system:tbGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tbGoodsService.selectTbGoodsById(id));
    }

    /**
     * 新增商品
     */
    @ApiOperation(value = "新增商品",notes = "")
    @PreAuthorize("@ss.hasPermi('system:tbGoods:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbGoods tbGoods) {
        return toAjax(tbGoodsService.insertTbGoods(tbGoods));
    }

    /**
     * 修改商品
     */
    @ApiOperation(value = "修改商品",notes = "")
    @PreAuthorize("@ss.hasPermi('system:tbGoods:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbGoods tbGoods) {
        return toAjax(tbGoodsService.updateTbGoods(tbGoods));
    }

    /**
     * 删除商品
     */
    @ApiOperation(value = "删除商品",notes = "")
    @PreAuthorize("@ss.hasPermi('system:tbGoods:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbGoodsService.deleteTbGoodsByIds(ids));
    }
}
